﻿using ATMClientWinForm.ATMService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATMClientWinForm
{
    public partial class InformationTransfer : Form
    {
        Account account;
        ATMService.ATMServiceSoapClient client;

        public InformationTransfer(Account accountEntity)
        {
            InitializeComponent();
            client = new ATMServiceSoapClient();
            this.account = accountEntity;
            LoadInformation();
            //LoadReceivedTransfer();
            //LoadSendTransfer();
            //LoadWithdrawalMoney();

        }
        void LoadInformation()
        {
            lblName.Text = this.account.Name;
            lblIp.Text = this.account.Ip;
            lblBalabce.Text = this.account.Balance.ToString();
            lblTitle.Text = "Welcome " + this.account.Name + "to Bank";
            LoadHistory();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            ManageATM ad = new ManageATM(this.account);
            ad.Show();
            this.Close();

        }

        void LoadHistory() {
            List<Transaction> lstHistory = new List<Transaction>();
            Transaction[] t = client.GetHistoryTransaction(this.account.Ip);
            if (t != null) {
                foreach (Transaction item in t)
                {
                    lstHistory.Add(item);
                }
                dgvHistory.DataSource = lstHistory;
            }
        }

        //void LoadReceivedTransfer()
        //{
        //    List<Transaction> list = new List<Transaction>();
        //    Transaction[] Sendign = client.GetReceivedTransfer(this.account.Ip);
        //    if (Sendign != null)
        //    {
        //        foreach (Transaction item in Sendign)
        //        {
        //            list.Add(item);
        //        }
        //        foreach (var item in list)
        //        {
        //            ListViewItem lvi = new ListViewItem(item.IpFrom);
        //            lvi.SubItems.Add(item.IpTo);
        //            lvi.SubItems.Add(item.Money.ToString());
        //            lvi.SubItems.Add(item.Time.ToString());
        //            lvRe.Items.Add(lvi);
        //        }
        //    }

        //}
        //void LoadSendTransfer()
        //{
        //    List<SendingAccountEntity> list = new List<SendingAccountEntity>();
        //    SendingAccountEntity[] Sendign = client.GetSendTransfer(this.account.Ip);
        //    if (Sendign != null)
        //    {
        //        foreach (SendingAccountEntity item in Sendign)
        //        {
        //            list.Add(item);
        //        }
        //        foreach (var item in list)
        //        {
        //            ListViewItem lvi = new ListViewItem(item.IpFrom);
        //            lvi.SubItems.Add(item.IpTo);
        //            lvi.SubItems.Add(item.Money.ToString());
        //            lvi.SubItems.Add(item.Time.ToString());
        //            lvSend.Items.Add(lvi);
        //        }
        //    }
            
        //    }
        //void LoadWithdrawalMoney()
        //{
        //    List<SendingAccountEntity> list = new List<SendingAccountEntity>();
        //    SendingAccountEntity[] Sendign = client.WithdrawMoney(this.account.Ip);
        //    if (Sendign != null)
        //    {
        //        foreach (SendingAccountEntity item in Sendign)
        //        {
        //            list.Add(item);
        //        }
        //        foreach (var item in list)
        //        {
        //            ListViewItem lvi = new ListViewItem(item.IpFrom);
        //            lvi.SubItems.Add(item.Money.ToString());
        //            lvi.SubItems.Add(item.Time.ToString());
        //            lvWithdralMoney.Items.Add(lvi);
        //        }
        //    }

        //}

        }

    }

